<?php

class TeacherPeer extends BaseTeacherPeer
{
/*
	public static getTeacherByAccount( $teacherAccount )
	{
		return DbFinder::from('teacher a')
		->where('a.teacherAccountName', $teacherAccount)
		->findOne()
		;
	}
*/	
	public static function chk_TeacherByAccount( $as_usname, $as_password, $as_endcode = 1 )
	{
		//1 : ok 0:invalid
		//endcode = 1:sha1, 2:md5
		$record = DbFinder::from('Teacher a')
		->where('a.teacherAccountName', $as_usname)
		->findOne()
		;
		if(!$record)
			return 0;//invalid
		else
		{
			$db_pwd = $record->getTeacherPassword();
			switch ($as_endcode)
			{
				case 1: //sha1
					$endcode_pwd = sha1($as_password);
					break;
				case 2: //md5
					$endcode_pwd = md5($as_password);
					break;
			}
			if( $endcode_pwd == $db_pwd )
				return 1; //valid
			else
				return 0;//invalid
		}
	}
	//check login for student
		public static function chk_StudentByAccount( $as_usname, $as_password, $as_endcode = 1 )
	{
		//1 : ok 0:invalid
		//endcode = 1:sha1, 2:md5
		$record = DbFinder::from('Student a')
		->where('a.stdAccountName', $as_usname)
		->findOne()
		;
		if(!$record)
			return 0;//invalid
		else
		{
			$db_pwd = $record->getStdPassword();
			switch ($as_endcode)
			{
				case 1: //sha1
					$endcode_pwd = sha1($as_password);
					break;
				case 2: //md5
					$endcode_pwd = md5($as_password);
					break;
			}
			if( $endcode_pwd == $db_pwd )
				return 1; //valid
			else
				return 0;//invalid
		}
	}
}
